package com.liuxvru.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.liuxvru.common.annotation.Log;
import com.liuxvru.common.core.controller.BaseController;
import com.liuxvru.common.core.domain.AjaxResult;
import com.liuxvru.common.enums.BusinessType;
import com.liuxvru.project.domain.Release;
import com.liuxvru.project.service.IReleaseService;
import com.liuxvru.common.utils.poi.ExcelUtil;
import com.liuxvru.common.core.page.TableDataInfo;

/**
 * 发布Controller
 * 
 * @author liuxvru
 * @date 2025-02-10
 */
@RestController
@RequestMapping("/project/release")
public class ReleaseController extends BaseController
{
    @Autowired
    private IReleaseService releaseService;

    /**
     * 查询发布列表
     */
    @PreAuthorize("@ss.hasPermi('project:release:list')")
    @GetMapping("/list")
    public TableDataInfo list(Release release)
    {
        startPage();
        List<Release> list = releaseService.selectReleaseList(release);
        return getDataTable(list);
    }

    /**
     * 导出发布列表
     */
    @PreAuthorize("@ss.hasPermi('project:release:export')")
    @Log(title = "发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Release release)
    {
        List<Release> list = releaseService.selectReleaseList(release);
        ExcelUtil<Release> util = new ExcelUtil<Release>(Release.class);
        util.exportExcel(response, list, "发布数据");
    }

    /**
     * 获取发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:release:query')")
    @GetMapping(value = "/{releaseId}")
    public AjaxResult getInfo(@PathVariable("releaseId") Long releaseId)
    {
        return success(releaseService.getById(releaseId));
    }

    /**
     * 新增发布
     */
    @PreAuthorize("@ss.hasPermi('project:release:add')")
    @Log(title = "发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Release release)
    {
        return toAjax(releaseService.save(release));
    }

    /**
     * 修改发布
     */
    @PreAuthorize("@ss.hasPermi('project:release:edit')")
    @Log(title = "发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Release release)
    {
        return toAjax(releaseService.updateById(release));
    }

    /**
     * 删除发布
     */
    @PreAuthorize("@ss.hasPermi('project:release:remove')")
    @Log(title = "发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{releaseIds}")
    public AjaxResult remove(@PathVariable Long[] releaseIds)
    {
        return toAjax(releaseService.removeById(releaseIds));
    }
}
